package com.wzdigit.wms.wms.service.core.asn;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.asn.AsnDtlGoods;
import com.wzdigit.wms.basic.mapper.core.order.AsnDtlGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 收货通知单明细货品清单 服务类
 * </p>
 *
 * @author
 * @since 2021-01-12
 */
@Service
@Slf4j
public class AsnDtlGoodsService {

    @Autowired
    AsnDtlGoodsMapper asnDtlGoodsMapper;

    public AsnDtlGoodsMapper getMapper() {
        return asnDtlGoodsMapper;
    }


    /**
     * 根据传入的实体，新增一条记录
     *
     * @param asnDtlGoods
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public AsnDtlGoods addNewOne(AsnDtlGoods asnDtlGoods) {

        int row = asnDtlGoodsMapper.insert(asnDtlGoods);
        log.info("成功新增{}条数据", row);

        return asnDtlGoods;
    }

    /**
     * 根据入参更新值
     *
     * @param asnDtlGoods
     * @return
     */
    public AsnDtlGoods updateOne(AsnDtlGoods asnDtlGoods) {

        int row = asnDtlGoodsMapper.updateById(asnDtlGoods);
        log.info("成功新增{}条数据", row);
        return asnDtlGoods;
    }

    /**
     * 根据【收货通知单明细ID集合】查询【收货通知单货品清单】集合
     *
     * @param asnDtlIdList
     * @return
     */
    public List<AsnDtlGoods> getByAsnDtlIdList(List<Integer> asnDtlIdList) {
        if (asnDtlIdList.size() > 0) {
        	QueryWrapper<AsnDtlGoods> wrapper = new QueryWrapper<>();
            wrapper.in("ASN_DTL_ID", asnDtlIdList);
            return asnDtlGoodsMapper.selectList(wrapper);
        }
        return new ArrayList<>(0);
    }

    /**
     * 根据[收货通知明细]查询[收货通知明细货品清单]
     *
     * @param asnDtlId
     * @return
     */
    public List<AsnDtlGoods> getByAsnDtlId(Integer asnDtlId) {
        QueryWrapper<AsnDtlGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ASN_DTL_ID", asnDtlId);
        return this.asnDtlGoodsMapper.selectList(queryWrapper);
    }
}
